/*
 File Name: srtp.h
 
 
 
 Description:
 This header file provides some basic definitions for the implementation
 of a Simple Reliable Transport Protocol (SRTP).
 
 
 */


/************** Definitions ***********************/

/*** Misc constants ***/

#define SRTP_MAX_PAYLOAD_SIZE	4000
#define SRTP_MAX_SEND_BUF_SIZE  4000


/*** SRTP packet types ***/
#define SRTP_TYPE_DATA	1	/* Data packet */
#define SRTP_TYPE_ACK	2	/* Acknowledgement packet*/
#define SRTP_TYPE_SYN	3	/* SYN packet, initiates connection setup */ 
#define SRTP_TYPE_FIN	4	/* FIN packet, initiates closing of connection */
#define SRTP_TYPE_RSTzz	5	/* Reset packet, resets connection */


/*** SRTP connection states ***/

/* client and server */
#define SRTP_STATE_ESTABLISHED	1
#define SRTP_STATE_CLOSED		2

/* client only states */
#define SRTP_STATE_SYN_SENT		3
#define SRTP_STATE_FIN_WAIT		4  

/* server only states */
#define SRTP_STATE_LISTEN		5
#define SRTP_STATE_TIME_WAIT	6



/*************** Data Structures ********************/

/*** SRTP Header ***/

struct srtp_hdr{
	uint32_t type;
	uint32_t seqnbr;
};

/*** SRTP Packet **/
#pragma pack(1)
struct pktbuf{
	struct srtp_hdr hdr;		
    struct srtp_hdr serv_hdr;
    // size of payload in bytes
	int len;							 
	char payload[SRTP_MAX_PAYLOAD_SIZE];
};
#pragma pack(0)


/*** Protocol Control Block (PCB) structures ***/

/* client PCB */
struct srtp_client_pcb{
    // corresponding UDP socket
	int sockfd;		
    // connection state: CLOSED, ESTABLISHED, SYN_SENT or FIN_WAIT
	int state;		
    // you need to define SRTP_MAX_SEND_BUF_SIZE
	struct pktbuf send_buf[SRTP_MAX_SEND_BUF_SIZE]; 
    // stores the destination IP
	char destination_IP[32];   
    // stores the destination portnumber
    int destination_port;
    // buffer to send
	char buffer_pcb[SRTP_MAX_SEND_BUF_SIZE];
    
};



/* server PCB */
struct srtp_server_pcb{
	// corresponding UDP socket
    int sockfd; 
    // connection state: CLOSED, ESTABLISHED, LISTEN, FIN_WAIT
	int state;	
    // holds the server port number
    int server_port_num_pcb;
    // buffer received
    char buffer_spcb[200];
    // holding the seqnum of the client
    int  seqnum_client;
    // holding the last written out data seqnum
    int last_return;
    
};


